package nowcoder.offer;

import java.util.List;

/**
 * 删除链表中重复的结点
 *
 * @author briarbear
 * @blog https://briarbear.github.io
 * @date 2018-08-29 10:56
 */
public class DeleteDuplication {

    public ListNode solution(ListNode pHead){
        if (pHead == null)
            return null;
        ListNode res = new ListNode(-1);
        res.next = pHead;
        ListNode pre = res, next = pre.next;

        while (next!= null){
            int val = next.val;
            if(next.next != null && next.next.val == val){
                while (next != null && next.val == val) {
                    next = next.next;
                }
                pre.next = next;
            }else {
                pre = next;
                next = next.next;
            }

        }

        return res.next;
    }

    public static void main(String[] args) {
        ListNode root = new ListNode(1);
        root.next = new ListNode(1);
        root.next.next = new ListNode(1);
        root.next.next.next = new ListNode(1);
        root.next.next.next.next = new ListNode(1);
        ListNode node = new DeleteDuplication().solution(root);
        System.out.println("");
    }
}
